package com.beiye.drivertransport.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.android.frame.adapter.CommonAdapter;
import com.android.frame.adapter.ViewHolder;
import com.beiye.drivertransport.R;
import com.beiye.drivertransport.bean.TwoMainCarBean;
import com.beiye.drivertransport.view.ShowGridView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ky on 2018/5/18.
 */


public class TwoMainApt extends CommonAdapter<TwoMainCarBean.RowsBean> {
    private final List<TwoMainCarBean.RowsBean> mList;
    private Context context;
    private String begin;
    private String end;


    public TwoMainApt(Context context, List<TwoMainCarBean.RowsBean> mList, int itemLayoutId) {
        super(context, mList, itemLayoutId);
        this.context = context;
        this.mList = mList;
    }



    @Override
    public void convert(ViewHolder holder, TwoMainCarBean.RowsBean item, final int position) {
        TwoMainCarBean.RowsBean dataBean=mList.get(position);
        ArrayList<TwoMainCarBean.RowsBean.MaintImgListBean> submaintImgList=new ArrayList<>();
        ArrayList<TwoMainCarBean.RowsBean.StandImgListBean> substandImgList=new ArrayList<>();
        TextView tv_date = holder.getView(R.id.tv_two_maintennance2);//维护日期
        TextView tv_total = holder.getView(R.id.tv_two_maintennance);//总路程
        TextView tv_Maintenance= holder.getView(R.id.tv_two_maintennance11);//维护单位
        TextView tv_hegecode = holder.getView(R.id.tv_two_maintennance12);//合格证
        TextView tv_nextdate = holder.getView(R.id.tv_two_maintennance7);//下期维护
//        ImageView img_twomainitem = holder.getView(R.id.img_twomainitem);//维护照片1
//        ImageView img_twomainitem1 = holder.getView(R.id.img_twomainitem1);//维护照片2
//        ImageView img_twomainitem2 = holder.getView(R.id.img_twomainitem2);//维护照片3
//        ImageView img_twomainitem3 = holder.getView(R.id.img_twomainitem3);//维护照片4
//        RelativeLayout re_twomain = holder.getView(R.id.re_twomain);//维护照片布局
//        ImageView img_twomainitem4 = holder.getView(R.id.img_twomainitem10);//维护照片5
//        ImageView img_twomainitem5 = holder.getView(R.id.img_twomainitem5);//合格照片1
//        ImageView img_twomainitem6 = holder.getView(R.id.img_twomainitem6);//合格照片2
//        ImageView img_twomainitem7 = holder.getView(R.id.img_twomainitem7);//合格照片3
//        ImageView img_twomainitem8 = holder.getView(R.id.img_twomainitem8);//合格照片4
//        RelativeLayout re_twomain1 = holder.getView(R.id.re_twomain1);//合格照片布局
//        ImageView img_twomainitem9 = holder.getView(R.id.img_twomainitem11);//合格照片5
        ShowGridView gv_parent = holder.getView(R.id.gv_parent);
        ShowGridView gv_parent1 = holder.getView(R.id.gv_parent1);
        String maintDate = mList.get(position).getMaintDate();
        String nextMaintDate = mList.get(position).getNextMaintDate();
        String mOrgName = mList.get(position).getMOrgName();
        String qualNo = mList.get(position).getQualNo();
        float totalMile = mList.get(position).getTotalMile();
//        List<TwoMainCarBean.RowsBean.MaintImgListBean> maintImgList = mList.get(position).getMaintImgList();//维护照片
//        List<TwoMainCarBean.RowsBean.StandImgListBean> standImgList = mList.get(position).getStandImgList();//合格照片
        if(maintDate==null)
        {
            tv_date.setText("");
        }else{

            tv_date.setText(maintDate);
        }
        if(nextMaintDate==null)
        {
            tv_nextdate.setText("");
        }else{

            tv_nextdate.setText(nextMaintDate);
        }
        if(mOrgName==null)
        {
            tv_Maintenance.setText("");
        }else{

            tv_Maintenance.setText(mOrgName);
        }
        if(qualNo==null)
        {
            tv_hegecode.setText("");
        }else{

            tv_hegecode.setText(qualNo);
        }
        if(totalMile==0)
        {
            tv_total.setText("");
        }else{
            int totalMile1 = Math.round(totalMile);//froat转int类型
            tv_total.setText(totalMile1+"km");
        }
        if(dataBean.getMaintImgList()!=null&&dataBean.getMaintImgList().size()!=0) {
            gv_parent.setVisibility(View.VISIBLE);
            submaintImgList.clear();
            submaintImgList.addAll(mList.get(position).getMaintImgList());
            MaintImgAdapter maintImgAdapter = new MaintImgAdapter(context, submaintImgList);
            gv_parent.setAdapter(maintImgAdapter);
        }else {
           gv_parent.setVisibility(View.GONE);
        }



        if(dataBean.getStandImgList()!=null&&dataBean.getStandImgList().size()!=0)
        {
            gv_parent1.setVisibility(View.VISIBLE);
            substandImgList.clear();
            substandImgList.addAll(mList.get(position).getStandImgList());
            StandImgAdapter standImgAdapter = new StandImgAdapter(context, substandImgList);
            gv_parent1.setAdapter(standImgAdapter);
        }else{
            gv_parent1.setVisibility(View.GONE);
        }


//        String photoUrl1 = maintImgList.get(0).getUrl();
//        String photoUrl2 = maintImgList.get(1).getUrl();
//        String photoUrl3 = maintImgList.get(2).getUrl();
//        String photoUrl4 = maintImgList.get(3).getUrl();
//        String photoUrl5 = maintImgList.get(4).getUrl();
//      if(photoUrl1==null)
//      {
//
//      }else{
//          if(photoUrl2==null)
//          {
//
//              img_twomainitem1.setImageResource(R.mipmap.twomain);
//          }
//          Picasso.with(context).load(Uri.parse(photoUrl1)).placeholder(R.mipmap.no_data).into(img_twomainitem);//加载图片
//      }
//        if(photoUrl2==null)
//        {
//
//        }else{
//            if(photoUrl3==null)
//            {
//
//                img_twomainitem2.setImageResource(R.mipmap.twomain);
//            }
//            Picasso.with(context).load(Uri.parse(photoUrl2)).placeholder(R.mipmap.no_data).into(img_twomainitem1);//加载图片
//        }
//        if(photoUrl3==null)
//        {
//
//        }else{
//            if(photoUrl4==null)
//            {
//
//                img_twomainitem3.setImageResource(R.mipmap.twomain);
//            }
//            Picasso.with(context).load(Uri.parse(photoUrl3)).placeholder(R.mipmap.no_data).into(img_twomainitem2);//加载图片
//        }
//
//        if(photoUrl4==null)
//        {
//
//        }else{
//            if(photoUrl5==null)
//            {
//                re_twomain.setVisibility(View.VISIBLE);
//                img_twomainitem4.setImageResource(R.mipmap.twomain);
//            }
//            Picasso.with(context).load(Uri.parse(photoUrl4)).placeholder(R.mipmap.no_data).into(img_twomainitem3);//加载图片
//        }
//        if(photoUrl5==null)
//        {
//
//        }else{
//
//            re_twomain.setVisibility(View.VISIBLE);
//            Picasso.with(context).load(Uri.parse(photoUrl5)).placeholder(R.mipmap.no_data).into(img_twomainitem4);//加载图片
//        }
//
//        String rphotoUrl1 = standImgList.get(0).getUrl();
//        String rphotoUrl2 = standImgList.get(1).getUrl();
//        String rphotoUrl3 = standImgList.get(2).getUrl();
//        String rphotoUrl4 = standImgList.get(3).getUrl();
//        String rphotoUrl5 = standImgList.get(4).getUrl();
//        if(rphotoUrl1==null)
//        {
//
//        }else{
//            if(rphotoUrl2==null)
//            {
//
//                img_twomainitem6.setImageResource(R.mipmap.twomain);
//            }
//            Picasso.with(context).load(Uri.parse(rphotoUrl1)).placeholder(R.mipmap.no_data).into(img_twomainitem5);//加载图片
//        }
//        if(rphotoUrl2==null)
//        {
//
//        }else{
//            if(rphotoUrl3==null)
//            {
//
//                img_twomainitem7.setImageResource(R.mipmap.twomain);
//            }
//            Picasso.with(context).load(Uri.parse(rphotoUrl2)).placeholder(R.mipmap.no_data).into(img_twomainitem6);//加载图片
//        }
//        if(rphotoUrl3==null)
//        {
//
//        }else{
//            if(rphotoUrl4==null)
//            {
//
//                img_twomainitem8.setImageResource(R.mipmap.twomain);
//            }
//            Picasso.with(context).load(Uri.parse(rphotoUrl3)).placeholder(R.mipmap.no_data).into(img_twomainitem7);//加载图片
//        }
//
//        if(rphotoUrl4==null)
//        {
//
//        }else{
//            if(rphotoUrl5==null)
//            {
//                re_twomain1.setVisibility(View.VISIBLE);
//                img_twomainitem9.setImageResource(R.mipmap.twomain);
//            }
//            Picasso.with(context).load(Uri.parse(rphotoUrl4)).placeholder(R.mipmap.no_data).into(img_twomainitem8);//加载图片
//        }
//        if(rphotoUrl5==null)
//        {
//
//        }else{
//
//            re_twomain1.setVisibility(View.VISIBLE);
//            Picasso.with(context).load(Uri.parse(rphotoUrl5)).placeholder(R.mipmap.no_data).into(img_twomainitem9);//加载图片
//        }




    }


}